package com.scott.crm.base.interceptor.cross;

import com.scott.crm.base.utils.DataUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2021-12-05 11:58:13
 */
@Slf4j
@Component
public class CrossOriginInterceptor implements HandlerInterceptor {

    public void crossDomain(HttpServletRequest request, HttpServletResponse response) {

        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET, PATCH, DELETE, PUT");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "*");
    }
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("---------进入[跨域]拦截器校验preHandle token---------");
        crossDomain(request,response);
        return  true;


    }
}
